package com.cltech.entity.sys;

import com.cltech.entity.BaseEntity;
import com.fasterxml.jackson.annotation.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by Administrator on 2018/9/5.
 */
@Getter
@Setter
@Entity
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,property = "id")
public class SysPermission extends BaseEntity {
    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    private String id;
    private String name;
    private String link;
    private Integer level;
    private String type;
    private String icon;
    private Integer sortNo;
    @ManyToOne(cascade = {CascadeType.MERGE})
    @JoinColumn(name = "parent_id")
    @JsonIgnore
    private SysPermission parent;
    @JsonIgnore
    private String parentIds;
    private String permissionCode;
    private String description;
    @JsonIgnore
    @OneToMany(cascade = {CascadeType.REMOVE}, fetch = FetchType.LAZY, mappedBy = "parent")
    private Set<SysPermission> children = new HashSet<>();
    @JsonIgnore
    @ManyToMany
    @JoinTable(name="sys_permission_role",joinColumns=@JoinColumn(name="permission_id"),
            inverseJoinColumns=@JoinColumn(name="role_id"))
    private Set<SysRole> roles = new HashSet<>();

}
